package mainFrame;

import context.*;

import javax.swing.JPanel;
import javax.swing.BoxLayout;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import javax.swing.JLabel;
import javax.swing.BorderFactory;

import util.PixelPoint;
import util.UTM32Grid;
import util.UTM32Location;

// ***************************************************************************
// *** CLASS: StatusLine
// ***************************************************************************
public class StatusLine extends JPanel implements Context.Constants
{ //private static final boolean DEBUG=true; // Overriding Context.Constants.DEBUG
  static final long serialVersionUID=0; // AD'HOC
  static final String TAG="mainFrame.StatusLine";

  private LoweredLabel description;
  private LoweredLabel scale;
  private LoweredLabel mode;
  private LoweredLabel locationX,locationY;
  private LoweredLabel positionX,positionY;
  
  // *************************************************************************
  // *** CONSTRUCTOR: StatusLine
  // *************************************************************************
  public StatusLine()
  { super();
    setLayout(new BoxLayout(this,BoxLayout.X_AXIS));
    setAlignmentX(LEFT_ALIGNMENT);

    add(new JSeparator(SwingConstants.VERTICAL));
    add(description=new LoweredLabel());
    add(locationX=new LoweredLabel());  add(locationY=new LoweredLabel());
    add(positionX=new LoweredLabel());  add(positionY=new LoweredLabel());
    add(scale=new LoweredLabel());
    add(mode=new LoweredLabel()); 

    setDescription("");
    setScale("1:500");
    setMode("");

  }

  // *************************************************************************
  // *** METHODS
  // *************************************************************************
  public void setDescription(String text) { description.setText(" "+text+' '); }
  public void setMode(String text) { mode.setText(" Mouse: "+text+' '); }
  public void setScale(String text) { scale.setText(" Scale: "+text+' '); }

//  public void setLocation(UTM32Location location)
//  { locationX.setText("UTM32 X: "+((location==null)?"unknown":location.getEast())+" E ");
//    locationY.setText("UTM32 Y: "+((location==null)?"unknown":location.getNorth())+" N ");
//  }

  public void setMousePosition(UTM32Grid grid,PixelPoint pixelPoint)
  { positionX.setText(" X: "+((pixelPoint==null)?"unknown":pixelPoint.getX())+' ');
    positionY.setText(" Y: "+((pixelPoint==null)?"unknown":pixelPoint.getY())+' ');
    UTM32Location location=pixelPoint.toUTM32Location(grid);
    locationX.setText("UTM32 X: "+((location==null)?"unknown":location.getEast())+" E ");
    locationY.setText("UTM32 Y: "+((location==null)?"unknown":location.getNorth())+" N ");
  }
}

// ***************************************************************************
// *** LOCAL CLASS: LoweredLabel
// ***************************************************************************
class LoweredLabel extends JLabel
{ static final long serialVersionUID=0; // AD'HOC

  public LoweredLabel()
  { setBorder(BorderFactory.createLoweredBevelBorder());
    setHorizontalAlignment(SwingConstants.CENTER);
  }
}